//package com.site.springboot.core.config;
//
//import com.site.springboot.core.filter.JwtAuthenticationTokenFilter;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.security.SecurityProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpMethod;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
//import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.web.SecurityFilterChain;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
//
///**
// * Project:springboot-project-news-publish-system
// * ClassName:SpringSecurityConfig
// * Package:com.site.springboot.core.config
// * User:CWQ
// * Description:
// *
// * @Author 合肥-陈万琼
// * @Create 2024/5/27 20:02
// * @Version 1.0
// */
//@EnableWebSecurity
//@EnableMethodSecurity
//@Configuration
//public class SpringSecurityConfig  {
//    @Autowired
//    private UserDetailsService userDetailsService;
//
//    @Autowired
//    private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
//
////    配置密码加密器
//    @Bean
//    public PasswordEncoder passwordEncoder() {
//        return new BCryptPasswordEncoder();
//    }
//
//    @Bean
//    public DaoAuthenticationProvider authenticationProvider() {
//        DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
//        authenticationProvider.setUserDetailsService(userDetailsService);
//        authenticationProvider.setPasswordEncoder(passwordEncoder());
//        return authenticationProvider;
//    }
//    //认证器管理器-登录时会用到
//    @Bean
//    public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception {
//        return http.getSharedObject(AuthenticationManagerBuilder.class)
//                .authenticationProvider(authenticationProvider()).build();
//    }
//
//    //自定义配置
////    @Bean
////    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
////        http
////                .csrf(AbstractHttpConfigurer::disable)
////
////
////                .httpBasic(AbstractHttpConfigurer::disable)
////
////
////                .formLogin(formLogin ->
////                        formLogin
////                                .loginPage("/login.html") // 设置登录页面路径
////                                .loginProcessingUrl("/admin/login") // 设置登录处理路径
////                                .defaultSuccessUrl("/index.html", true)// 设置登录成功后跳转路径
////                )
////
////
////                .logout(logout ->
////                        logout
////                                .logoutUrl("/perform_logout") // 设置登出路径
////                                .logoutSuccessUrl("/login.html")
////                )
////
////
////                .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
////
////
////                .authorizeHttpRequests((request) -> {
////                    request.requestMatchers(HttpMethod.OPTIONS,"/**").permitAll()
////                            .requestMatchers(HttpMethod.POST, "/admin/login").permitAll()
////                            .requestMatchers(HttpMethod.POST, "/login.html").permitAll()
////                            .anyRequest().authenticated(); }
////                )
////
////                .authorizeHttpRequests((request) -> {
////                    request.requestMatchers(HttpMethod.OPTIONS,"/**").permitAll()
////                            .requestMatchers(HttpMethod.POST, "/admin/login").permitAll()
////                            .requestMatchers(HttpMethod.POST, "/login.html").permitAll()
////                            .anyRequest().authenticated();
////                })
////
////                .addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
////
////
////        return http.build();
////
////    }
//    @Bean
//    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
//        http.csrf(AbstractHttpConfigurer::disable)
//                .httpBasic(AbstractHttpConfigurer::disable)
////                .formLogin(AbstractHttpConfigurer::disable)
//
//
//                .formLogin(formLogin ->
//                        formLogin
//                                .loginPage("/admin/H5login.html") // 设置登录页面路径
//                                .loginProcessingUrl("/admin/token") // 设置登录处理路径
//                                .defaultSuccessUrl("/admin/index.html", true)// 设置登录成功后跳转路径
//                )
//
//
//                .logout(AbstractHttpConfigurer::disable)
//                .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
//                .authorizeHttpRequests((request) -> {request
//                        .requestMatchers(HttpMethod.OPTIONS,"/**").permitAll()
//                        .requestMatchers(HttpMethod.POST, "/admin/token").permitAll()
////                        .requestMatchers(HttpMethod.GET, "/**/*.html", "/**/*.js", "/**/*.css", "/**/*.jpg", "/**/*.png").permitAll()
//                        .anyRequest().authenticated(); })
//                .addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
//        return http.build();
//    }
//
//    @Bean
//    public WebSecurityCustomizer webSecurityCustomizer() {
//        return (web) -> web.ignoring().requestMatchers(new AntPathRequestMatcher("/**/*.html", "GET"), new AntPathRequestMatcher("/admin/token", "POST"));
//    }
//}
